#!/usr/bin/env bash
cd ${0%/*} || exit 1    # run from this directory

# Source tutorial run functions
. $WM_PROJECT_DIR/bin/tools/RunFunctions

# Copy initial conditions
cp -rf 0.org 0

runApplication blockMesh
runApplication snappyHexMesh -overwrite
runApplication topoSet

if [ "$1" = "-parallel" ]
    then
    if [[ $WM_PROJECT_VERSION == "3."* ]]
        then
        nProc=$(getNumberOfProcessors)
    else
        nProc=""
    fi
    runApplication decomposePar
    ls -d processor* | xargs -I {} rm -rf ./{}/0
    ls -d processor* | xargs -I {} cp -r 0.org ./{}/0
    runParallel pimpleFoam  $nProc
    runApplication reconstructPar
else
    runApplication pimpleFoam
fi
